function _defineProperty(a, t, e) {
    return t in a ? Object.defineProperty(a, t, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[t] = e, a;
}

var app = getApp();

function qrcode(a) {
    var t = require("../../../utils/wxqrcode.js").createQrCodeImg(a, {
        size: 300
    });
    return console.log(t), t;
}

Page({
    data: {
        top: 0,
        nav: {
            0: "全部",
            "-1": "待领取",
            x2: "已领取",
            "-2": "已过期"
        },
        navCur: 0,
        list: [],
        load: -1,
        page: 1,
        pagesize: 15,
        loading: !1,
        loadend: !1,
        qrcode: !1
    },
    contactSeller: function(a) {
        console.log(a.currentTarget.dataset.value), wx.makePhoneCall({
            phoneNumber: a.currentTarget.dataset.value
        });
    },
    restpage: function() {
        this.data.page = 1, this.data.loading = !1, this.data.loadend = !1, this.setData({
            loadend: !1
        }), this.setData({
            list: []
        });
    },
    loadpagedata: function(a) {
        var n = this;
        if (a && this.restpage(), 1 != this.data.loadend) {
            if (1 == this.data.loading) return app.look.no("加载中"), void n.setData({
                msg: " "
            });
            app.util.showLoading(), app.util.request({
                url: "entry/wxapp/package",
                showLoading: !1,
                data: {
                    op: "getorder",
                    status: "x2" == this.data.navCur ? "2" : this.data.navCur,
                    page: this.data.page,
                    papagesizege: this.data.pagesize
                },
                success: function(a) {
                    var t = a.data.data.list;
                    if (console.log(n.data.page), 1 == n.data.page) n.setData({
                        list: t
                    }); else {
                        var e = n.data.list.concat(t);
                        n.setData({
                            list: e
                        });
                    }
                    n.data.page++, n.setData({
                        msg: "",
                        page: this.data.page + 1
                    });
                },
                fail: function(a) {
                    n.data.loadend = !0, n.setData({
                        msg: "我是有底线的~"
                    });
                },
                complete: function() {
                    n.data.loading = !1;
                }
            });
        } else app.look.no("加载完成");
    },
    click_nav: function(a) {
        var t = a.currentTarget.id;
        this.setData({
            navCur: t
        }), this.loadpagedata(!0);
    },
    click_get: function(a) {
        var t = "../awardMall/awardMall?id=" + this.data.list[a.currentTarget.dataset.id].packageid;
        wx.navigateTo({
            url: t
        });
    },
    copyText: function(a) {
        wx.setClipboardData({
            data: a.currentTarget.dataset.text,
            success: function(a) {
                wx.getClipboardData({
                    success: function(a) {
                        wx.showToast({
                            title: "复制成功"
                        });
                    }
                });
            }
        });
    },
    to_see: function(a) {
        var t = a.currentTarget.dataset.index;
        console.log(a);
        var e = "../shipped/shipped?id=" + this.data.list[t].id;
        wx.navigateTo({
            url: e
        });
    },
    confirmreceipt: function(a) {
        var e = a.currentTarget.dataset.index, n = this;
        wx.showModal({
            title: "提示",
            content: "是否确认收货",
            success: function(a) {
                a.confirm ? app.util.request({
                    url: "entry/wxapp/package",
                    showLoading: !1,
                    data: {
                        op: "confirmreceipt",
                        id: n.data.list[e].id
                    },
                    success: function(a) {
                        a.data;
                        var t = n.data.list;
                        t[e].status = 3, n.setData({
                            list: t
                        });
                    }
                }) : a.cancel && console.log("用户点击取消");
            }
        });
    },
    onPageScroll: function(a) {
        var t = a.scrollTop;
        this.setData({
            top: t
        });
    },
    pickCode: function(a) {
        var t = a.currentTarget.dataset.index, e = this.data.list;
        this.setData({
            hex: qrcode("666_" + e[t].redeemcode + "#" + e[t].id),
            qrcode: !0
        });
    },
    hideQrcode: function() {
        this.setData({
            qrcode: !1
        });
    },
    pay_order: function(e) {
        var a = this.data.list[e.currentTarget.dataset.index].id, n = this;
        app.util.request({
            url: "entry/wxapp/package",
            showLoading: !1,
            data: {
                op: "pay_order",
                id: a
            },
            success: function(a) {
                if (a.data && a.data.data && !a.data.errno) {
                    var t = a.data.data.tid;
                    wx.requestPayment({
                        timeStamp: a.data.data.timeStamp,
                        nonceStr: a.data.data.nonceStr,
                        package: a.data.data.package,
                        signType: "MD5",
                        paySign: a.data.data.paySign,
                        success: function(a) {
                            setTimeout(function() {
                                !function a(t) {
                                    app.util.request({
                                        url: "entry/wxapp/payquery",
                                        showLoading: !1,
                                        data: {
                                            tid: t
                                        },
                                        success: function(a) {
                                            app.globalData.userInfo = a.data.data, n.setData(_defineProperty({}, "list[" + e.currentTarget.dataset.index + "].ispay", 1));
                                        },
                                        fail: function() {
                                            setTimeout(function() {
                                                a(t);
                                            }, 1e3);
                                        }
                                    });
                                }(t);
                            }, 500);
                        },
                        fail: function(a) {
                            a.errMsg;
                        }
                    });
                }
            }
        });
    },
    onLoad: function(a) {
        var t = a.status;
        "x2" == t && this.setData({
            navCur: t
        }), console.log(a), this.loadpagedata();
    },
    onReady: function() {
        app.look.footer(this), app.look.navbar(this);
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        var e = this;
        this.setData({
            value: ""
        }), app.util.request({
            url: "entry/wxapp/package",
            showLoading: !0,
            method: "POST",
            data: {
                op: "getorder",
                page: 1,
                pagesize: e.data.pagesize,
                status: "x2" == this.data.navCur ? "2" : this.data.navCur
            },
            success: function(a) {
                wx.stopPullDownRefresh();
                var t = a.data;
                console.log(t), t.data.list && e.setData({
                    list: t.data.list,
                    page: 1,
                    loadend: !1,
                    earth: !0
                });
            },
            fail: function(a) {
                app.look.alert(a.data.message), e.setData({
                    loadend: !0
                });
            }
        });
    },
    onReachBottom: function() {
        this.loadpagedata();
    },
    onShareAppMessage: function() {}
});